# encoding=utf-8
import pytest
from common.config import *


def pytest_addoption(parser):
    parser.addoption("--env", action="store", default="test", help="choose environment")
    parser.addoption("--branchId", action="store", default="23141", help="choose branchId")
    parser.addoption("--input1", action="store", default="10.1.106.18")
    parser.addoption("--input2", action="store", default="cc:4b:73:7b:9f:0a")


@pytest.fixture()
def env(request):
    return request.config.getoption('--env')


@pytest.fixture
def branchId(request):
    return request.config.getoption("--branchId")


# def pytest_configure(config):
#     marker_list = ["P0","P1","P2"]  # 标签名集合
#     for markers in marker_list:
#         config.addinivalue_line("markers", markers)


@pytest.fixture()
def input1(request):
    return request.config.getoption("--input1")


@pytest.fixture()
def input2(request):
    return request.config.getoption("--input2")


def pytest_configure(config):
    config.addinivalue_line(
        "markers", "coolguy"
    )
    environment = config.getoption('--env')
    pytest.global_env = environment


'''
契望成登录token
'''


@pytest.fixture(scope="function")
def qwc_token(env):
    print("获取契望成商家后台登录token")
    base_url = getconf(env, "qwc_url")
    url = base_url + "flashmall-main/v1/session/login"
    headers = {"content-type": "application/json;charset=UTF-8", "application": "cms"}
    dict = {"account": getconf(env, "qwc_user"), "password": getconf(env, "qwc_pwd"), "accountType": "BRANCH_ADMIN",
            "clientId": 1}
    r = requests.post(url, json=dict, headers=headers)
    token = r.json()['token']
    print("返回：" + token)
    yield token

    print("执行完成了qwc_token")


'''
契望成供应商登录token清除
'''


@pytest.fixture(scope="function")
def supplier_clear():
    clear_supplier_cookie()
